package com.source.adnroid.comm.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.source.android.androidcomm.R;

import java.util.ArrayList;

/**
 * Created by zzw on 2018/4/3.
 */

public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.ViewHolder>{
    private ArrayList<String> mData;
    OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener ){
        this. onItemClickListener=onItemClickListener;
    }
    public UserListAdapter(ArrayList<String> data) {
        this.mData = data;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_chat_msg, parent, false);
        // 实例化viewholder
        UserListAdapter.ViewHolder viewHolder = new UserListAdapter.ViewHolder(v);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.chatToMsg.setText("群聊"+position);
        holder.chatToMsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public  class ViewHolder extends RecyclerView.ViewHolder {
        TextView chatToMsg;

        public ViewHolder(View itemView) {
            super(itemView);
            chatToMsg =itemView.findViewById(R.id.chat_to_msg);

        }
    }
}
